home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / Mem_PrintStats.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  8.9 KB  |  394 lines

  1. head     1.5;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.5.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.5
  10. date     89.02.10.09.54.31;  author brent;  state Exp;
  11. branches 1.5.1.1;
  12. next     1.4;
  13.  
  14. 1.4
  15. date     89.01.30.15.39.53;  author brent;  state Exp;
  16. branches ;
  17. next     1.3;
  18.  
  19. 1.3
  20. date     88.07.25.14.51.44;  author ouster;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.07.25.14.19.25;  author ouster;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.05.20.15.49.24;  author ouster;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34. 1.5.1.1
  35. date     91.12.02.20.37.59;  author kupfer;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.5
  45. log
  46. @Fixed typo
  47. @
  48. text
  49. @/* 
  50.  * Mem_PrintStats.c --
  51.  *
  52.  *    Source code for the "Mem_PrintStats" library procedure.  See memInt.h
  53.  *    for overall information about how the allocator works..
  54.  *
  55.  * Copyright 1988 Regents of the University of California
  56.  * Permission to use, copy, modify, and distribute this
  57.  * software and its documentation for any purpose and without
  58.  * fee is hereby granted, provided that the above copyright
  59.  * notice appear in all copies.  The University of California
  60.  * makes no representations about the suitability of this
  61.  * software for any purpose.  It is provided "as is" without
  62.  * express or implied warranty.
  63.  */
  64.  
  65. #ifndef lint
  66. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/Mem_PrintStats.c,v 1.4 89/01/30 15:39:53 brent Exp $ SPRITE (Berkeley)";
  67. #endif not lint
  68.  
  69. #include "memInt.h"
  70.  
  71. /*
  72.  * Data structure used to record statistics for the blocks managed by
  73.  * the large block allocator.  Each entry holds information for all the
  74.  * blocks of a given size.
  75.  */
  76.  
  77. #define    MAX_TO_PRINT    256
  78. static struct {
  79.     int        size;        /* Size of the block. */
  80.     int        num;        /* Number of blocks allocated. */
  81.     int        free;        /* Number of blocks freed. */
  82.     int        inUse;        /* Number of blocks still in use. */
  83.     int        dummy;        /* Number of blocks used as dummy blocks. */
  84. } topN[MAX_TO_PRINT + 1];
  85.  
  86. /*
  87.  * Global variables that can be set to control thresholds for printing
  88.  * statistics.
  89.  */
  90.  
  91. int    mem_SmallMinNum = 1;        /* There must be at least this many
  92.                      * binned objects of a size before info
  93.                      * about its size gets printed. */
  94. int    mem_LargeMinNum  = 1;        /* There must be at least this many
  95.                      * non-binned objects of a size before
  96.                      * info about the size gets printed. */
  97. int    mem_LargeMaxSize = 10000;    /* Info is printed for non-binned
  98.                      * objects larger than this regardless
  99.                      * of how many of them there are. */
  100.  
  101. /*
  102.  * Forward declarations to procedures defined in this file:
  103.  */
  104.  
  105. extern void    PrintStatsSubr();
  106.  
  107. /*
  108.  *----------------------------------------------------------------------
  109.  *
  110.  * Mem_PrintStats --
  111.  *
  112.  *    Print out memory statistics, using the default printing routine
  113.  *    and default sizes.
  114.  *
  115.  *    See Mem_PrintStatsInt for details.
  116.  *
  117.  * Results:
  118.  *    None.
  119.  *
  120.  * Side effects:
  121.  *    None.
  122.  *
  123.  *----------------------------------------------------------------------
  124.  */
  125. ENTRY void
  126. Mem_PrintStats()
  127. {
  128.     LOCK_MONITOR;
  129.  
  130.     Mem_PrintStatsInt();
  131.  
  132.     UNLOCK_MONITOR;
  133. }
  134.  
  135. /*
  136.  *----------------------------------------------------------------------
  137.  *
  138.  * Mem_PrintStatsInt --
  139.  *
  140.  *    Print out memory statistics.  Normally called only by
  141.  *    Mem_PrintStats.  It's exported for use after a crash or when
  142.  *    memory has been exhausted.  At this time the monitor lock is
  143.  *    already down, so it better not be reacquired.
  144.  *
  145.  * Results:
  146.  *    None.
  147.  *
  148.  * Side effects:
  149.  *    Information gets printed, using the current print procedure
  150.  *    and the parameter values stored in mem_SmallMinNum,
  151.  *    mem_LargeMinNum, and mem_LargeMaxSize.
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155.  
  156. INTERNAL void
  157. Mem_PrintStatsInt()
  158. {
  159.     register Address    ptr;
  160.     register int    i;
  161.     int        totalBlocks, totalFree;
  162. #ifdef MEM_TRACE
  163.     int totalAllocs;
  164. #endif
  165.     int        allocBytes = 0;
  166.     int        freeBytes = 0;
  167.     int        warnedAboutOverflow;
  168.  
  169.     if (!memInitialized) {
  170.     (*memPrintProc)(memPrintData, "Allocator not initialized yet.\n");
  171.     return;
  172.     }
  173.  
  174. #ifdef MEM_TRACE
  175.     (*memPrintProc)(memPrintData, "\nTotal allocs = %d, frees = %d\n\n",
  176.         mem_NumAllocs, mem_NumFrees);
  177.     totalAllocs = 0;
  178. #else
  179.     (*memPrintProc)(memPrintData, "Memory tracing not enabled, so %s",
  180.         "some statistics won't be printed.\n");
  181. #endif
  182.  
  183.     (*memPrintProc)(memPrintData, "Small object allocator:\n");
  184.     (*memPrintProc)(memPrintData,
  185.         "    Size     Total    Allocs    In Use\n");
  186.     totalBlocks = totalFree = 0;
  187.     for (i = 2; i < BIN_BUCKETS; i++) {
  188.     int    numFree = 0;
  189.  
  190.     if ((memFreeLists[i] == NOBIN) || (mem_NumBlocks[i] == 0)) {
  191.         continue;
  192.     }
  193.     allocBytes += mem_NumBlocks[i] * INDEX_TO_BLOCKSIZE(i);
  194.     for (ptr = memFreeLists[i]; 
  195.          ptr != (Address) NULL; 
  196.          ptr = (Address) GET_ADMIN(ptr)) {
  197.  
  198.         freeBytes += INDEX_TO_BLOCKSIZE(i);
  199.         numFree += 1;
  200.     }
  201.     if (mem_NumBlocks[i] >= mem_SmallMinNum) {
  202. #ifdef MEM_TRACE
  203.         (*memPrintProc)(memPrintData, "%8d%10d%10d%10d\n",
  204.             INDEX_TO_BLOCKSIZE(i),
  205.             mem_NumBlocks[i], mem_NumBinnedAllocs[i],
  206.             mem_NumBlocks[i] - numFree);
  207. #else
  208.         (*memPrintProc)(memPrintData, "%8d%10d%10s%10d\n", 
  209.             INDEX_TO_BLOCKSIZE(i),
  210.             mem_NumBlocks[i], "??", mem_NumBlocks[i] - numFree);
  211. #endif MEM_TRACE
  212.     }
  213.     totalBlocks += mem_NumBlocks[i];
  214. #ifdef MEM_TRACE
  215.     totalAllocs += mem_NumBinnedAllocs[i];
  216. #endif
  217.     totalFree += numFree;
  218.     }
  219. #ifdef MEM_TRACE
  220.     (*memPrintProc)(memPrintData, "   Total%10d%10d%10d\n", totalBlocks,
  221.         totalAllocs, totalBlocks - totalFree);
  222. #else
  223.     (*memPrintProc)(memPrintData, "   Total%10d%10s%10d\n", totalBlocks,
  224.         "??", totalBlocks - totalFree);
  225. #endif
  226.     (*memPrintProc)(memPrintData, "Bytes allocated = %d, free = %d\n\n",
  227.                 allocBytes, freeBytes);
  228.  
  229.     /*
  230.      * Initialize the largest N-sizes buffer.
  231.      */
  232.     for (i = 0; i < MAX_TO_PRINT + 1; i++) {
  233.     topN[i].size = -1;
  234.     topN[i].free = 0;
  235.     topN[i].dummy = 0;
  236.     }
  237.  
  238.     warnedAboutOverflow = 0;
  239.     freeBytes = 0;
  240.     for (ptr = memFirst + SIZE(GET_ADMIN(memFirst)); 
  241.      ptr != memLast;
  242.      ptr += SIZE(GET_ADMIN(ptr))) {
  243.  
  244.     int    admin;
  245.     int    size;
  246.     int    found;
  247.  
  248.     admin = GET_ADMIN(ptr);
  249.     if (!IS_DUMMY(admin) && !IS_IN_USE(admin)) {
  250.         freeBytes += SIZE(admin);
  251.     }
  252.  
  253.     size = SIZE(admin);
  254. #ifdef MEM_TRACE
  255.     if ((size - GET_ORIG_SIZE(ptr) < 4) && 
  256.         (size - GET_ORIG_SIZE(ptr) >= 0)) {
  257.         size = GET_ORIG_SIZE(ptr);
  258.     }
  259. #endif MEM_TRACE
  260.  
  261.     found = 0;
  262.     for (i = 0; i < MAX_TO_PRINT; i++) {
  263.         if (size == topN[i].size) {
  264.         found = 1;
  265.         topN[i].num++;
  266.         if (IS_DUMMY(admin)) {
  267.             topN[i].dummy++;
  268.         } else if (IS_IN_USE(admin)) {
  269.             topN[i].inUse++;
  270.         } else {
  271.             topN[i].free++;
  272.         }
  273.         break;
  274.         } else if (topN[i].size == -1) {
  275.         found = 1;
  276.         topN[i].size = size;
  277.         topN[i].num = 1;
  278.         if (IS_DUMMY(admin)) {
  279.             topN[i].dummy = 1;
  280.         } else if (IS_IN_USE(admin)) {
  281.             topN[i].inUse = 1;
  282.         } else {
  283.             topN[i].free = 1;
  284.         }
  285.         break;
  286.         }
  287.     }
  288.  
  289.     if (!found && !warnedAboutOverflow) {
  290.         (*memPrintProc)(memPrintData,
  291.             "Ran out of large-object bins: needed more than %d.\n",
  292.             size);
  293.         warnedAboutOverflow = 1;
  294.     }
  295.     }
  296.     (*memPrintProc)(memPrintData, "Large object allocator:\n");
  297.     (*memPrintProc)(memPrintData, "   Total bytes managed: %d\n",
  298.         mem_NumLargeBytes);
  299.     (*memPrintProc)(memPrintData, "   Bytes in use:        %d\n",
  300.                     mem_NumLargeBytes - freeBytes);
  301.     (*memPrintProc)(memPrintData, "%10s%10s%10s%10s\n", 
  302. #ifdef MEM_TRACE
  303.         "Orig. Size", "Num", "Free", "In Use");
  304. #else
  305.         "Size", "Num", "Free", "In Use");
  306. #endif MEM_TRACE
  307.     for (i = 0; topN[i].size != -1; i++) {
  308.     if (((topN[i].num >= mem_LargeMinNum)
  309.         || (topN[i].size >= mem_LargeMaxSize))
  310.         && (topN[i].num != topN[i].dummy)) {
  311.         (*memPrintProc)(memPrintData, "%10d%10d%10d%10d\n",
  312.         topN[i].size, topN[i].num, topN[i].free, topN[i].inUse);
  313.     }
  314.     }
  315. }
  316. @
  317.  
  318.  
  319. 1.5.1.1
  320. log
  321. @Initial branch for Sprite server.
  322. @
  323. text
  324. @d18 1
  325. a18 1
  326. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/Mem_PrintStats.c,v 1.5 89/02/10 09:54:31 brent Exp $ SPRITE (Berkeley)";
  327. @
  328.  
  329.  
  330. 1.4
  331. log
  332. @Fixed these trace routines to print out the correct bucket sizes
  333. @
  334. text
  335. @d18 1
  336. a18 1
  337. static char rcsid[] = "$Header: Mem_PrintStats.c,v 1.3 88/07/25 14:51:44 ouster Exp $ SPRITE (Berkeley)";
  338. d161 1
  339. a161 1
  340.             INDEX_TO_BLOCKSIZE,
  341. @
  342.  
  343.  
  344. 1.3
  345. log
  346. @Lint.
  347. @
  348. text
  349. @d18 1
  350. a18 1
  351. static char rcsid[] = "$Header: Mem_PrintStats.c,v 1.2 88/07/25 14:19:25 ouster Exp $ SPRITE (Berkeley)";
  352. d145 1
  353. a145 1
  354.     allocBytes += mem_NumBlocks[i] * 4 * i;
  355. d150 1
  356. a150 1
  357.         freeBytes += 4 * i;
  358. d155 2
  359. a156 1
  360.         (*memPrintProc)(memPrintData, "%8d%10d%10d%10d\n", 4*i,
  361. d160 2
  362. a161 1
  363.         (*memPrintProc)(memPrintData, "%8d%10d%10s%10d\n", 4*i,
  364. @
  365.  
  366.  
  367. 1.2
  368. log
  369. @Lint.
  370. @
  371. text
  372. @d18 1
  373. a18 1
  374. static char rcsid[] = "$Header: Mem_PrintStats.c,v 1.1 88/05/20 15:49:24 ouster Exp $ SPRITE (Berkeley)";
  375. d129 1
  376. d138 1
  377. a138 1
  378.     totalBlocks = totalAllocs = totalFree = 0;
  379. @
  380.  
  381.  
  382. 1.1
  383. log
  384. @Initial revision
  385. @
  386. text
  387. @d18 1
  388. a18 1
  389. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  390. d113 4
  391. a116 1
  392.     int        totalBlocks, totalAllocs, totalFree;
  393. @
  394.